import { Models } from "../../../common/typings/model";
import KoaRouter from 'koa-router'
import Mysql from "../../../core/Mysql";
import Result from "../../../common/utils/Result";
import httpErrors from '../../../core/HttpException'
import config from '../../../config/config'
import loginSchema from '../../../common/apiValidate/user/login'
import validator from '../../../middlewares/validator'
import bcrypt from "bcryptjs"
import utils from '../../../common/utils/Utils'
import Auth from '../../../middlewares/Auth'
const router = new KoaRouter({
    prefix:'/api/v1/router'
})



/*
 * 获取用户的路由信息
 * @param { appid } 项目appid
 * @param { string } account ,邮箱, type为101时必填
 * @param { string } secret ,密码，type为101时必填
 * @param { string } code ，微信code ，type为100时必填
 * @return { string } token  成功返回token
 */
router.get('/getRouter.do',Auth.verifyToken,async (ctx: Models.Ctx,next:Function)=> {
    let role = ''
    if(ctx.auth){
        role = ctx.auth.scope
    }
    let appId = ctx.request.query.appId
    // role 字段，角色，与权限相关
    const res = await Mysql.query(`
        SELECT 
            router
        FROM 
            router
        where 
            router.role <= '${role}' and
            router.app_id = '${appId}'
    `)
    throw new httpErrors.Success(res.results[0],'登录成功')

    
})


export default router